#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void *thread_func(void *arg)
{
    int i = 0;
    while(1)
    {
        printf("i=%d\n",i++);
        sleep(1);
        if(i == 10)
        pthread_exit(NULL);
    }
}

int main(int argc, char const *argv[])
{
    // 初始化线程属性
    pthread_attr_t attr;
    pthread_attr_init(&attr);

    // 获取线程属性
    unsigned long stacksize1;
    pthread_attr_getstacksize(&attr,&stacksize1);
    printf("stacksize=%ld\n",stacksize1);

    // 设置线程属性
    pthread_attr_setstacksize(&attr, 1024*1024);


    pthread_t tid;
    pthread_create(&tid, &attr, thread_func, NULL);

    unsigned long stacksize2;
    pthread_attr_getstacksize(&attr,&stacksize2);
    printf("stacksize=%ld\n",stacksize2);

    pthread_join(tid, NULL);
    pthread_attr_destroy(&attr);

    return 0;
}
